/*
    Android UIML

	Copyright (C) 2010  Bram Goffings (bramgoffings@gmail.com)

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public License
	as published by the Free Software Foundation; either version 2.1
	of	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

package uiml.android.elements.peers;

import java.util.ArrayList;

import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

import uiml.android.elements.UimlElementWithAttributes;

public class DComponent extends  UimlElementWithAttributes {
	
	// TODO comment
	private ArrayList<DMethod> dmethods = new ArrayList<DMethod>();
	
	private String mapsTo = null;
	private String location = null;

	// TODO comment
	public static String IAM = "d-component";
	public final String DMETHOD = "d-method";
	public final String MAPSTO = "maps-to";
	public final String LOCATION = "location";
	

	/**
	 * 
	 * @param node
	 */
	public DComponent(Element node) {
		super(node);
		process();
	}

	/**
	 * 
	 */
	@Override
	protected Object clone() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void process() {
		processAttributes();
		super.process();
	}
	
	/**
	 * 
	 */
	@Override
	public void processElement(Element elem) {
		
		if(elem.getTagName().equals(DMETHOD))
			dmethods.add(new DMethod(elem));
	}
	
	/**
	 * 
	 */
	@Override
	public void processAttributes() {
		
		super.processAttributes();
		
		NamedNodeMap attributes = node.getAttributes();
		
		if(attributes != null) {
			if(attributes.getNamedItem(MAPSTO) != null)
				setMapsTo(attributes.getNamedItem(MAPSTO).getNodeValue());
			if(attributes.getNamedItem(LOCATION) != null)
				setLocation(attributes.getNamedItem(LOCATION).getNodeValue());
		}
	}

	/**
	 * @param mapsTo the mapsTo to set
	 */
	public void setMapsTo(String mapsTo) {
		this.mapsTo = mapsTo;
	}

	/**
	 * @return the mapsTo
	 */
	public String getMapsTo() {
		return mapsTo;
	}

	/**
	 * @param location the location to set
	 */
	public void setLocation(String location) {
		this.location = location;
	}

	/**
	 * @return the location
	 */
	public String getLocation() {
		return location;
	}

	/**
	 * @param dcomponents the dcomponents to set
	 */
	public void setDMethods(ArrayList<DMethod> dmethods) {
		this.dmethods = dmethods;
	}

	/**
	 * @return the dcomponents
	 */
	public ArrayList<DMethod> getDMethods() {
		return dmethods;
	}
}
